package fr.alesia.deepstack.io.impl;

import com.google.appengine.api.users.User;

import fr.alesia.deepstack.bean.Player;
import fr.alesia.deepstack.factory.BeanFactory;
import fr.alesia.deepstack.io.BeanReader;

public class PlayerReader implements BeanReader<Player> {

	private static BeanReader<Player> instance = null;
	
	private PlayerReader(){}
	
	public static BeanReader<Player> getInstance(){
		if(instance == null){
			instance = new PlayerReader();
		}
		return instance;
	}
	
	public Player read(String line) {
		
		String[] tokens = line.split(",");
		if(tokens.length == 2 || tokens.length == 3){
			
			String id = "k" + tokens[0];
			String name = tokens[1];
			//String email = tokens[2];
			//User user = UserServiceFactory.getUserService().getCurrentUser();
			User user = null;
			
			Player player = BeanFactory.createPlayer(name, user);
			player.setId(id);
			return player;
		}
		else{
			return null;
		}
	}
}
